package com.zhiquan.cai.service.impl;

import com.zhiquan.cai.dao.UserDao;
import com.zhiquan.cai.entity.User;
import com.zhiquan.cai.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findByUsername(String username) {
        return this.userDao.findByUsername(username);
    }

    @Override
    @Transactional
    public void userAdd(User user) {
        this.userDao.save(user);
        int a = 10/0;//测试抛出除数不为零的异常，事务回滚
    }

    @Override
    public Page<User> userGetAll(Pageable pageable) {
        return this.userDao.findAll(pageable);
    }

}
